package tmproject.hlhj.fhp.cartrans.modules

import android.content.Context
import com.example.mymvp.BaseModule
import com.lzy.okgo.model.Response
import tmproject.hlhj.fhp.cartrans.convert.MyException
import tmproject.hlhj.fhp.cartrans.http.Apis
import tmproject.hlhj.fhp.cartrans.http.BaseAciton
import tmproject.hlhj.fhp.cartrans.http.BaseObserver
import tmproject.hlhj.fhp.cartrans.http.LoadingAction
import tmproject.hlhj.fhp.cartrans.javaBean.BaseBean
import tmproject.hlhj.fhp.cartrans.javaBean.ClassListBean
import tmproject.hlhj.fhp.cartrans.javaBean.ExamTImesBean
import tmproject.hlhj.fhp.cartrans.javaBean.ReViewListBean

/**
 * Created by Administrator on 2018/8/26/026.
 */
class ReViewModule : BaseModule {
    var listener:OnLearnLisener?=null
    fun getReviewList(context: Context,token:String?,page:Int){
        Apis.getReviewList(token,page)
                ?.let {
                    it.doOnSubscribe(LoadingAction(context,false))
                            .subscribe(object :BaseObserver<Response<ReViewListBean>>(context){
                                override fun failed(e: Throwable?) {
                                }

                                override fun httpSuccess(t: Response<ReViewListBean>) {
                                    listener?.classResp(t.body())
                                }

                                override fun onError(e: Throwable) {
                                    if (e is MyException){
                                        if (e.code==408){
                                            listener?.noMore()
                                        }else{

                                        }
                                    }
                                }
                                override fun httpErroCode(baseBean: BaseBean) {
                                }
                            })
                }
      /*  Apis.getClassList(context)
                .doOnSubscribe(LoadingAction(context))
                .subscribe(object : BaseAciton<Response<ClassListBean>> {
                    override fun httpFailed(e: Throwable?) {

                    }
                    override fun httpSuccess(t: Response<ClassListBean>) {

                    }

                    override fun httpErroCode(t: Response<ClassListBean>) {
                    }
                })*/
    }

    fun getExamTimes(token: String?,context: Context){
        Apis.getExamTimes(token)
                ?.let {
                    it.doOnSubscribe(LoadingAction(context))
                            .subscribe(object :BaseObserver<Response<ExamTImesBean>>(context){
                                override fun failed(e: Throwable?) {
                                }

                                override fun httpSuccess(t: Response<ExamTImesBean>) {
                                    listener?.gotExamTimes(t.body())
                                }

                                override fun httpErroCode(baseBean: BaseBean) {
                                }
                            })
                }
    }
    interface OnLearnLisener{
        fun classResp(reViewListBean: ReViewListBean)

        fun noMore()
        fun gotExamTimes(examTImesBean: ExamTImesBean)
    }
}